#!/usr/bin/envpython
# -*-coding:UTF-8-*-
'''
@File    :   employee_queryEmployee.py
@Contact :   308711822@qq.com
@License :   (C) Copyright 2021-2225, Personal exclusive right.

@Modify Time      @Author    @Version    @Desciption
------------      -------    --------    -----------
2023/5/30 22:03   小钟同学      1.0         None
'''
from infirmary_admin_src.infirmary_common.infirmary_controller import IBaseController
from infirmary_admin_src.infirmary_common.infirmary_controller.rest_controller_with_depends import \
    RestControllerWithDepends
from fastapi import Request, Depends, Path, Body

from infirmary_admin_src.infirmary_smart_admin.infirmary_biz.infirmary.businesses.schemas import SchemaBase
from infirmary_admin_src.infirmary_smart_admin.infirmary_biz.system.role.services import RoleBusinesses
from infirmary_admin_src.infirmary_smart_admin.infirmary_utils.convert2_help import convert_dict_to_camel_case


class XParam(SchemaBase):
    '''
    账号密码登录参数
    '''
    pageNum: int = 1
    pageSize: int = 10
    keywords: str = ''
    role_id: int = Body(..., alias='roleId', title="roleId", description='roleId')

class IController(IBaseController):
    '''
    定制相关约束检测函数逻辑步序
    '''

    def __init__(self, *, request: Request,
                 schema_param: XParam,
                 ):
        super().__init__(request=request)
        # 入参参数
        # 入参参数
        self.schema_param = schema_param


@RestControllerWithDepends()
class SystemRoleEmployeeQueryEmployeeController(IController):

    def business_login(self):
        pass
        # 查询这个角色下所有的用户信息

        _result_nums_total, lists = RoleBusinesses.get_admin_sys_role_for_employee_info(
            keyword=self.schema_param.keywords,
            role_id=self.schema_param.role_id,
            pageNum=self.schema_param.pageNum,
            pageSize=self.schema_param.pageSize,
        )
        # 查询所有角色信息，进行匹配管理显示
        listdata = None
        if lists:
            listdata = [convert_dict_to_camel_case(v, keepkey=['departmentId', 'employeeId', 'gender', 'sort'],
                                                   delkeys=['loginPwd']) for v in lists]
        return {
            'emptyFlag': False if _result_nums_total > 0 else True,
            'list': listdata if listdata else [],
            'pageNum': self.schema_param.pageNum,
            'pageSize': self.schema_param.pageSize,
            'pages': 2,
            'total': _result_nums_total
        }
